/*
   Copyright 2009 Bloo. All Rights Reserved.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package org.youtensils.www.client.widgets.dialogs;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * A dialog box alerting the user that the required Java plugin was not detected.
 * @author Bobby Soares
 */
public class JavaRequiredDialog extends Dialog {
	private VerticalPanel contentPane;
	private HorizontalPanel buttonPane;
	/**
	 *  A constructor specifying the handler for the dialog's buttons.
	 * @param haveJavaHandler
	 */
	public JavaRequiredDialog(ClickHandler haveJavaHandler) {
		super("Java Plugin Required", true);
		this.contentPane = new VerticalPanel();
		this.contentPane.setWidth("500px");
		this.buttonPane = new HorizontalPanel();
		this.contentPane.add(new HTML("YouTensils.org requires the Java plugin Version 6 which was not " +
				"detected on your system."));
		Button getJava = new Button("Install Java (new window)");
		Button haveJava = new Button("I already have Java");
		getJava.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				JavaRequiredDialog.this.hide();
				Window.open("http://www.java.com/en/download/", "GetJava", "");
			}
		});
		haveJava.addClickHandler(haveJavaHandler);
		haveJava.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				JavaRequiredDialog.this.hide();
			}
		});;
		closeButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				JavaRequiredDialog.this.hide();
			}
		});
		this.buttonPane.add(getJava);
		this.buttonPane.add(haveJava);
		this.buttonPane.setStylePrimaryName("gwt-Dialog-ButtonPane");
		this.contentPane.add(buttonPane);
		this.setContentWidget(this.contentPane);
	}
}

